﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using UserControl = System.Windows.Forms.UserControl;
using Marmat.Forms.Skin;

namespace Marmat.Template.WinForm
{
    /// <summary>
    /// 边框文本编辑框
    /// </summary>
    internal partial class UnderlineTextBox : UserControl
    {
        public UnderlineTextBox()
        {
            InitializeComponent();
            this.watermarkTextBox1.GotFocus += WatermarkTextBox1_GotFocus;
            this.watermarkTextBox1.LostFocus += WatermarkTextBox1_LostFocus;
        }
        private void WatermarkTextBox1_LostFocus(object sender, EventArgs e)
        {
            this.color = Color.FromArgb(238, 238, 238);
            this.Invalidate();
        }

        private void WatermarkTextBox1_GotFocus(object sender, EventArgs e)
        {
            this.color = Color.FromArgb(113, 106, 186);
            this.Invalidate();
        }

        [Description("编辑框的图标")]
        [DefaultValue(null)]
        public Image Icon
        {
            get => this.label1.Image;
            set
            {
                this.label1.Image = value;
            }
        }
        private Color color = Color.FromArgb(238, 238, 238);

        [Description("编辑框的提示文本")]
        [DefaultValue("")]
        public string WatermarkText
        {
            get => this.watermarkTextBox1.WatermarkText;
            set => this.watermarkTextBox1.WatermarkText = value;
        }

        /// <summary>
        /// 编辑框的文本
        /// </summary>
        [Description("编辑框的文本")]
        [DefaultValue("")]
        public string Value
        {
            get => this.watermarkTextBox1.Text;
            set => this.watermarkTextBox1.Text = value;
        }

        /// <summary>
        /// 获取或设置用于对单个行中的密码掩码字符的字符 System.Windows.Forms.TextBox 控件。
        /// </summary>
        [Description("获取或设置用于对单个行中的密码掩码字符的字符 System.Windows.Forms.TextBox 控件。")]
        public char PasswordChar
        {
            get => this.watermarkTextBox1.PasswordChar;
            set => this.watermarkTextBox1.PasswordChar = value;
        }
        public void ResetPasswordChar()
        {
            this.PasswordChar = default;
        }
        public bool ShouldSerializePasswordChar()
        {
            return this.PasswordChar != default;
        }

        private void UnderlineTextBox_Paint_1(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            var rec = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
            var path = rec.GetRoundPath(5);
            e.Graphics.DrawPath(new Pen(color), path);
        }
    }
}
